----------------------------------------------------------------------------------
--
-- scenetemplate.lua
--
----------------------------------------------------------------------------------

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

----------------------------------------------------------------------------------
-- 
--	NOTE:
--	
--	Code outside of listener functions (below) will only be executed once,
--	unless storyboard.removeScene() is called.
-- 
---------------------------------------------------------------------------------

---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------

--Variable
	local imgBackground
	local myText
	local myPicture
--Listener Function
local function onSceneTouch( self, event )
	if event.phase == "began" then
		if (self.id == "myText") then
			imgBackground = display.newImageRect("background.png",_G.STAGE_WIDTH,_G.STAGE_HEIGHT )
			imgBackground:setReferencePoint( display.TopLeftReferencePoint )
			imgBackground.x = STAGE_LEFT
			imgBackground.y = STAGE_TOP
			imgBackground.id = "imgBackground"
		end
		return true
	end
end
local function pictureOnTouch(self,event)
	if event.phase == "began" then
		if (self.id == "myPicture") then
			print("myPicture")
		end
		return true
	end
end


-- Called when the scene's view does not exist:
function scene:createScene( event )
	local screenGroup = self.view

	imgBackground = display.newImageRect("bkg.png",_G.STAGE_WIDTH,_G.STAGE_HEIGHT )
	imgBackground:setReferencePoint( display.TopLeftReferencePoint )
	imgBackground.x = STAGE_LEFT
	imgBackground.y = STAGE_TOP
	imgBackground.id = "imgBackground"
	screenGroup:insert(imgBackground)

	myText = display.newText( "click here", 0, 0, native.systemFont, 24 )
	myText:setTextColor( 255 )
	myText.x, myText.y = display.contentWidth * 0.5,display.contentHeight * 0.5 - 100
	myText.touch = onSceneTouch
	myText.id = "myText"
	screenGroup:insert(myText)

	myPicture = display.newImageRect("picture.png",150,100)
	myPicture.x, myPicture.y = display.contentWidth * 0.5,display.contentHeight * 0.5
	myPicture.touch = pictureOnTouch
	myPicture.id = "myPicture"
	screenGroup:insert(myPicture)
	-----------------------------------------------------------------------------
		
	--	CREATE display objects and add them to 'group' here.
	--	Example use-case: Restore 'group' from previously saved state.
	
	-----------------------------------------------------------------------------
end


-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
	local screenGroup = self.view
	
	-----------------------------------------------------------------------------
		
	--	INSERT code here (e.g. start timers, load audio, start listeners, etc.)
	
	-----------------------------------------------------------------------------
	--Add Listeners
	myText:addEventListener( "touch", myText)
	myPicture:addEventListener( "touch", myPicture)
end


-- Called when scene is about to move offscreen:
function scene:exitScene( event )
	local screenGroup = self.view
	
	-----------------------------------------------------------------------------
	
	--	INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
	
	-----------------------------------------------------------------------------
	--Remove Listeners
	myText:removeEventListener( "touch", myText)
	myPicture:removeEventListener( "touch", myPicture)
end


-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
	local screenGroup = self.view
	
	-----------------------------------------------------------------------------
	
	--	INSERT code here (e.g. remove listeners, widgets, save state, etc.)
	
	-----------------------------------------------------------------------------
	
end

---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------

-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )

-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )

-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )

-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )

---------------------------------------------------------------------------------

return scene